package shims

import "unicode"
import "substr"

type Range []unicode.Range

//Is every char in s within Range?
func (r Range) Match(s []byte) bool {
	for _, v := range []int(string(s)) {
		if unicode.Is(r, v) {
			return true
		}
	}
	return false
}
//Find all continuous regions of s that are in Range
func (r Range) Find(s []byte, n int) *substr.S {
	//hardly optimally efficient, but shows off some of the features.
	return Runes.Find(s, -1).Keep(r).MergeConsecutive().Trunc(n)
}

//Find all substrings that aren't whitespace
var ws Range = unicode.White_Space
var Fields FreeFinder = func(s []byte, n int) *substr.S {
	m := n
	if m > 0 {
		m += 2
	}
	return ws.Find(s, m).Invert().Trunc(n)
}
